//
//  RoundDisPlayViewController.m
//  05-HomeWork
//
//  Created by 鹏飞罗 on 16/7/20.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "RoundDisPlayViewController.h"

@implementation RoundDisPlayViewController 

- (instancetype)initWithFrame:(CGRect)frame imageArray:(NSArray *)imageArray {
    self = [super init];
    if (self) {
        self.scrollerView = [[UIScrollView alloc] initWithFrame:frame];
        for (int i = 0; i < imageArray.count; i++) {
            UIScrollView *smallScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(i * frame.size.width, frame.origin.y, frame.size.width, frame.size.height)];
            UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, frame.size.width, frame.size.height)];
            imageView.image = [UIImage imageNamed:imageArray[i]];
            [smallScrollView addSubview:imageView];
            [self.scrollerView addSubview:smallScrollView];
        }
        self.imageArray = imageArray;
        self.frame = frame;
        self.scrollerView.contentSize = CGSizeMake(imageArray.count * frame.size.width, frame.size.height);
        self.scrollerView.contentOffset = CGPointMake(1 * frame.size.width, frame.origin.y);
        self.scrollerView.pagingEnabled = YES;
    }

    return self;
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    if (scrollView.contentOffset.x > (self.imageArray.count - 1) * self.frame.size.width ) {
        scrollView.contentOffset = CGPointMake(1 * self.frame.size.width, self.frame.origin.y);
    } else if (scrollView.contentOffset.x < 0) {
        scrollView.contentOffset = CGPointMake((self.imageArray.count - 2) * self.frame.size.width, self.frame.origin.y);
    }
}
@end
